package com.linxiao.hrcrm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.linxiao.hrcrm.domain.CrmCustomerSignIn;
import com.linxiao.hrcrm.service.ICrmCustomerSignInService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户签卡记录Controller
 *
 * @author zhoudong
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/hrcrm/signIn")
public class CrmCustomerSignInController extends BaseController {
    @Autowired
    private ICrmCustomerSignInService crmCustomerSignInService;

    /**
     * 查询客户签卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerSignIn crmCustomerSignIn) {
        startPage();
        List<CrmCustomerSignIn> list = crmCustomerSignInService.selectCrmCustomerSignInList(crmCustomerSignIn);
        return getDataTable(list);
    }

    /**
     * 查询客户签卡记录列表
     */
    @GetMapping("/findByUser")
    public TableDataInfo findByUser(CrmCustomerSignIn crmCustomerSignIn) {
        startPage();
        List<CrmCustomerSignIn> list = crmCustomerSignInService.findByUser(crmCustomerSignIn);
        return getDataTable(list);
    }

    /**
     * 导出客户签卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:export')")
    @Log(title = "客户签卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCustomerSignIn crmCustomerSignIn) {
        List<CrmCustomerSignIn> list = crmCustomerSignInService.selectCrmCustomerSignInList(crmCustomerSignIn);
        ExcelUtil<CrmCustomerSignIn> util = new ExcelUtil<CrmCustomerSignIn>(CrmCustomerSignIn.class);
        util.exportExcel(response, list, "客户签卡记录数据");
    }

    /**
     * 获取客户签卡记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(crmCustomerSignInService.selectCrmCustomerSignInById(id));
    }

    /**
     * 新增客户签卡记录
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:add')")
    @Log(title = "客户签卡记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCustomerSignIn crmCustomerSignIn) {
        return toAjax(crmCustomerSignInService.insertCrmCustomerSignIn(crmCustomerSignIn));
    }

    /**
     * 修改客户签卡记录
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:edit')")
    @Log(title = "客户签卡记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerSignIn crmCustomerSignIn) {
        return toAjax(crmCustomerSignInService.updateCrmCustomerSignIn(crmCustomerSignIn));
    }

    /**
     * 签卡审批通过
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:audits')")
    @Log(title = "签卡审批通过", businessType = BusinessType.UPDATE)
    @PutMapping("/audits/{id}")
    public AjaxResult audit(@PathVariable Long id) {
        return toAjax(crmCustomerSignInService.audits(id));
    }

    /**
     * 计算薪资
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:settle')")
    @Log(title = "计算薪资", businessType = BusinessType.UPDATE)
    @PostMapping("/settle/{ids}")
    public AjaxResult settle(@PathVariable Long[] ids) {
        return toAjax(crmCustomerSignInService.settle(ids));
    }

    /**
     * 删除客户签卡记录
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:signIn:remove')")
    @Log(title = "客户签卡记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmCustomerSignInService.deleteCrmCustomerSignInByIds(ids));
    }
}
